package com.example.composestudy.part6

import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.tooling.preview.Preview
import com.example.composestudy.utils.initialPage
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.HorizontalPager
import com.google.accompanist.pager.rememberPagerState

@Preview(showBackground = true)
@OptIn(ExperimentalPagerApi::class)
@Composable
fun DrawCircle() {
    val pageCount = 2
    val initialPage = 1.initialPage()
    val state = rememberPagerState(initialPage)
    HorizontalPager(count = pageCount, modifier = Modifier.fillMaxWidth(), state = state) { page ->
        when (page) {
            0 -> DrawCircle1()
            1 -> DrawCircle2()
        }
    }
}

@Composable
fun DrawCircle1() {
    PageItem(text = "DrawCircle1") {
        Canvas(modifier = Modifier.fillMaxSize()) {
            drawCircle(
                color = Color.Red,
                radius = 300f,
                center = center,
            )
        }
    }
}

@Composable
fun DrawCircle2() {
    PageItem(text = "DrawCircle2") {
        Canvas(modifier = Modifier.fillMaxSize()) {
            drawCircle(
                color = Color.Red,
                radius = 300f,
                center = center,
                style = Stroke(width = 30f)
            )
        }
    }
}